const puppeteer = require('puppeteer');
const fs = require('fs');

(async () => {
  const browser = await puppeteer.launch({executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'});
  const page = await browser.newPage();
 
 // await page.pdf({path: 'hn.pdf', format: 'A4'});

  let filelist = fs.readdirSync("result")
  for(let i = 0; i < filelist.length; i++){
    let filename = filelist[i];
    if(filename.indexOf(".html") == -1){
      continue
    }
    await page.goto('http://127.0.0.1:8081/'+filename);
    await page.pdf({path: 'pdf/'+filename+'.pdf', format: 'A4'});
  }
  await browser.close();
})();